package vn.fpt.fsoft.cuongn.faces.controller;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;

import vn.fpt.fsoft.cuongn.faces.bean.SelectItem;
import vn.fpt.fsoft.cuongn.faces.dao.ListAccountDAO;
import vn.fpt.fsoft.cuongn.faces.model.Account;

@ManagedBean(name = "selectItemController", eager = true)
@RequestScoped
public class SelectItemController {
	@ManagedProperty(value = "#{selectItem}")
	private SelectItem selectItem;
	private Integer value;
	public Integer getValue() {
		return value;
	}

	public void setValue(Integer value) {
		this.value = value;
	}

	ListAccountDAO listAccountDAO = new ListAccountDAO();
	public SelectItem getSelectItem() {
		return selectItem;
	}

	public void setSelectItem(SelectItem selectItem) {
		this.selectItem = selectItem;
	}
	
	public List<SelectItem> getAllAccount(){
		List<SelectItem> items = new ArrayList<SelectItem>();
		try {
			List<Account> categoryList = listAccountDAO.getAccounts();
			for(Account account : categoryList){
				items.add(new SelectItem(account.getId(), account.getHoTen()));
			}
			return items;
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		return null;
		
	}
	
	public String transfeData(){
		//getAllAccount();
		
		
		return "valueItem";
	}
	
}
